import { PageResult, WholeResult } from "@/store/module/types/comm/pageType";
import request from "@/utils/request";

enum API {
  BASE_URL = "/ums/admin/umsRole",
  ROLE_SHOWALL_PAGE = API.BASE_URL + "/showAllWithPage",
  ROLE_ADD_URL = API.BASE_URL + "/addRole",
  ROLE_DEL_URL = API.BASE_URL + "/delRole",
  ROLE_DELS_URL = API.BASE_URL + "/delRoles",
  ROLE_SWITCH_STATUS_URL = API.BASE_URL + "/switchStatus",
  ROLE_UPDATE_URL= API.BASE_URL + "/updateRole",
}
/**
 * 角色显示实体
 */
export interface RoleVo {
  id: number;
  name: string;
  description: string;
  admin_count: number;
  create_time: string;
  status: number;
}

/**
 * 分页参数封装对象
 */
export interface RolePageVo {
  pageSize: number;
  pageLimit: number;
  roleName: string;
}

/**
 * 封装分页处理方法
 * @param data 分页参数
 *  {pageSize : 1 pageLimit : 10 roleName:'a'}
 */
export const roleShowAllPage = (data: RolePageVo) =>
  request<WholeResult<RoleVo>>({
    url: API.ROLE_SHOWALL_PAGE,
    params: data,
  });

/**
 * 角色添加功能
 * @param data 角色实体
 * @returns true|false
 */
export const roleAdd = (data: RoleVo) =>
  request<boolean>({
    method: "POST",
    url: API.ROLE_ADD_URL,
    data: data,
  });

export const roleDelById = (id: number) =>
  request<WholeResult<boolean>>({
    method: "DELETE",
    url: API.ROLE_DEL_URL + "/" + id,
  });

export const roleDelByIds = (id: number[]) =>
  request<WholeResult<boolean>>({
    method: "DELETE",
    url: API.ROLE_DELS_URL,
    params: { ids: id + "" },
  });


export const switchStatus = (id:number) =>
  request<WholeResult<boolean>>({
    method: "PUT",
    url: API.ROLE_SWITCH_STATUS_URL+"/"+id,
  });


  export const updateById = (data : RoleVo)=>{
    return request<WholeResult<boolean>>({
      method: "PUT",
      url: API.ROLE_UPDATE_URL,
      data,
    });
  }